package com.maket.scxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.feign.GetCodeFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.GxProcess;
import com.maket.scxx.service.IGxProcessService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工序定义Controller
 * 
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/process")
public class GxProcessController extends BaseController
{
    @Autowired
    private IGxProcessService gxProcessService;

    /**
     * 查询工序定义列表
     */
    @RequiresPermissions("scxx:process:list")
    @GetMapping("/list")
    public TableDataInfo list(GxProcess gxProcess)
    {
        startPage();
        List<GxProcess> list = gxProcessService.selectGxProcessList(gxProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序定义列表
     */
    @RequiresPermissions("scxx:process:export")
    @Log(title = "工序定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxProcess gxProcess)
    {
        List<GxProcess> list = gxProcessService.selectGxProcessList(gxProcess);
        ExcelUtil<GxProcess> util = new ExcelUtil<GxProcess>(GxProcess.class);
        util.exportExcel(response, list, "工序定义数据");
    }

    /**
     * 获取工序定义详细信息
     */
    @RequiresPermissions("scxx:process:query")
    @GetMapping(value = "/{gxCode}")
    public AjaxResult getInfo(@PathVariable("gxCode") String gxCode)
    {
        return success(gxProcessService.selectGxProcessByGxCode(gxCode));
    }

    /**
     * 新增工序定义
     */
    @Autowired
    private GetCodeFeign getCodeFeign;
    @RequiresPermissions("scxx:process:add")
    @Log(title = "工序定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxProcess gxProcess)
    {
        String code = getCodeFeign.getUser(5);
        gxProcess.setGxCode(code);
        return toAjax(gxProcessService.insertGxProcess(gxProcess));
    }

    /**
     * 修改工序定义
     */
    @RequiresPermissions("scxx:process:edit")
    @Log(title = "工序定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxProcess gxProcess)
    {
        return toAjax(gxProcessService.updateGxProcess(gxProcess));
    }

    /**
     * 删除工序定义
     */
    @RequiresPermissions("scxx:process:remove")
    @Log(title = "工序定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxCodes}")
    public AjaxResult remove(@PathVariable String[] gxCodes)
    {
        return toAjax(gxProcessService.deleteGxProcessByGxCodes(gxCodes));
    }
}
